from rest_framework import serializers

from goods.models import SKU
from goods.search_indexes import SKUIndex


class CategoriesListSerializer(serializers.ModelSerializer):

    class Meta:
        model = SKU
        fields ='__all__'

from drf_haystack.serializers import HaystackSerializer


class SKUIndexSerializer(HaystackSerializer):
    """
    SKU索引结果数据序列化器
    """
    # 嵌套序列化返回
    object = CategoriesListSerializer(read_only=True)

    class Meta:
        index_classes = [SKUIndex]
        fields = ('text', 'object')